package vn.conghuy.talkwithme.data.livescore;

import java.util.ArrayList;


public class LivescoreLeague {
	public String name;
	ArrayList<LivescoreMatch> matches;
	
	public LivescoreLeague(){
		matches = new ArrayList<LivescoreMatch>();
	};
	public LivescoreLeague(String name, ArrayList<LivescoreMatch> matches) {
		super();
		matches = new ArrayList<LivescoreMatch>();
		this.name = name;
		this.matches = matches;
	}
	public void addMatch(LivescoreMatch match){
		matches.add(match);
	}
	
	/**
	 * Check if exist an element in array has name be a word in specified string
	 * @param arr contain leagues.
	 * @param str string specified
	 * @return exist or not
	 */
	public static ArrayList<LivescoreLeague> elementInArrayIsWordOfStr(ArrayList<LivescoreLeague> arr, String str){
		//TODO not done
		ArrayList<LivescoreLeague> leaguesResult = new ArrayList<LivescoreLeague>();
		for(LivescoreLeague league : arr){
			if(Utils.indexOfWord(league.name.toLowerCase(), str) != -1){
				leaguesResult.add(league);
			}
		}
		return leaguesResult;
	}
	
	public static ArrayList<LivescoreMatch> matchsInLeagueArrayHasTeamMatchKeyword(ArrayList<LivescoreLeague> arr, String str){
		ArrayList<LivescoreMatch> matchResults = new ArrayList<LivescoreMatch>();
		for(LivescoreLeague league: arr){
			for(LivescoreMatch match : league.matches){
				if(Utils.indexOfWord(match.home.toLowerCase(), str) != -1 
						|| Utils.indexOfWord(match.away.toLowerCase(), str) != -1
						|| Utils.indexOfWord(str, match.home.toLowerCase()) != -1
						|| Utils.indexOfWord(str, match.away.toLowerCase()) != -1){
					matchResults.add(match);
				}
			}
		}
		return matchResults;
	}
}
